package de.tabuma.pm.externalproject.logik;

import de.tabuma.pm.externalproject.entity.*;
import de.tabuma.pm.logik.*;

import java.util.*;
import java.util.logging.*;

/**
  * @author $Author: $
  * @version $Revision: $
  * @since $Date: $
 */
public class ExternalProjectFacade {
    
    private static final Logger log = Logger.getLogger(ExternalProjectFacade.class.getName());

    public static int create(ExternalProject eProject, String user) {
        return (int) PMF.doCreate(eProject, user);
    }

    public static void update(ExternalProject ep, String user) {
        PMF.doUpdate(ep, user);
    }

    public static ExternalProject get(int eprojectID) {
        return PMF.get(eprojectID, new ExternalProject());
    }

    public static void edit(ExternalProject externalProject, String user) {
        PMF.doUpdate(externalProject, user);
    }

    public static void remove(int eepID, String user) {
        ExternalProject ep = ExternalProjectFacade.get(eepID);
        PMF.doRemove(ep, user);
        removeParameter(eepID, user);
    }

    public static List<ExternalProject> getList(int projectID) {
        String keys[] = new String[1];
        keys[0] = "projectId";
        String values[] = new String[1];
        values[0] = ""+projectID;
        return PMF.get(keys, values, new ExternalProject());
    }

    public static void removeParameter(int externalProject, String user) {
        List<HiddenParameter> hpList = HiddenParameterFacade.getList(externalProject);
        for(int i=0;i<hpList.size();i++) {
            HiddenParameterFacade.remove(hpList.get(i).getId().intValue(), user);
        }
        List<LoginUserParameter> lupList = LoginUserParameterFacade.getList(externalProject);
        for(int i=0;i<lupList.size();i++) {
            LoginUserParameterFacade.remove(lupList.get(i).getId().intValue(), user);
        }
    }
}